package com.wiken.orderservice.rocketMQ;


import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.support.MessageBuilder;

@Configuration
public class OrderProducer {

    @Autowired
    RocketMQTemplate rocketMQTemplate;
    public void sendDelayMessage(String topic, String tags, Object message, int delayLevel) {
        try {

            rocketMQTemplate.asyncSend(topic, MessageBuilder.withPayload(message).build(), new SendCallback() {
                @Override
                public void onSuccess(SendResult sendResult) {
                    System.out.println("发送延迟消息成功");
                }

                @Override
                public void onException(Throwable throwable) {
                    System.out.println(throwable.getMessage());
                    System.out.println("发送失败");
                    System.out.println(throwable.getCause());
                }
            }, 10000, delayLevel);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
